package cn.yyt.yytravel.community.controller;

import cn.yyt.yytravel.base.response.JsonResult;
import cn.yyt.yytravel.community.pojo.dto.CommunityQuery;
import cn.yyt.yytravel.community.pojo.dto.CommunitySaveParam;
import cn.yyt.yytravel.community.pojo.dto.LikeCommunityParam;
import cn.yyt.yytravel.community.pojo.entity.Community;
import cn.yyt.yytravel.community.pojo.vo.CommunityVO;
import cn.yyt.yytravel.community.service.CommunityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/yyt/community/")
public class CommunityController {

    @Autowired
    CommunityService communityService;

    @PostMapping("save")
    public JsonResult save(CommunitySaveParam communitySaveParam){
        System.out.println(communitySaveParam);
        Community community = communityService.save(communitySaveParam);
        log.debug("返回的数据-出参{}",community);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult loadCommunity(CommunityQuery communityQuery){
        List<CommunityVO> list = communityService.selectCommunity(communityQuery);
        System.out.println(list);
        return JsonResult.ok(list);
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteCommunity(@PathVariable Long id){
        communityService.deleteCommunity(id);
        return JsonResult.ok();
    }

    @PostMapping("saveMyLikeCommunity")
    public JsonResult saveMyLikeCommunity(LikeCommunityParam likeCommunityParam){
        communityService.saveLikeC(likeCommunityParam);
        return JsonResult.ok();
    }

    @PostMapping("delMyLikeCommunity")
    public JsonResult delMyLikeCommunity(LikeCommunityParam likeCommunityParam){
        communityService.delLikeCommunity(likeCommunityParam);
        return JsonResult.ok();
    }
}
